
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;


public class Maschen {
	private CopyOnWriteArrayList<Mash> maschen;
	
	public Maschen (Graph g){
		ConcurrentHashMap<Integer , Mash> init= new ConcurrentHashMap<Integer, Mash>();
		
		for(Knoten k :g.getKnmap().values()){
			int id =k.getCapacity();
			Mash actMash;
			if(init.containsKey(id)){
				actMash =init.get(id);	
			}else{
				actMash =new Mash(id);
				init.put(id, actMash);
			}
			init.get(id).add(k);
			
		}
		maschen = new CopyOnWriteArrayList<Mash>(init.values());
		
	}
	
	public void add(Mash neu){
		maschen.add(neu);
	}
	
	public boolean containsMash(Mash m){
		return maschen.contains(m);
	}
	
//	public void checkMash(Mash m){
//		if (m.isempty()){
//			maschen.remove(m);
//		}
//	}

	public LinkedBlockingDeque<Mash> getMaschen() {
		return new LinkedBlockingDeque<Mash>(maschen);
	}
	
//	public void removeMash(Mash m){
//		maschen.remove(m);
//	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		for (Mash m : maschen){
		sb.append(" {{"+ m +"}} " );
		
		}
		return sb.toString();
	}
	
}
